﻿#include <iostream>
using namespace std;

#define  DELETE(pointer)  if(pointer){delete pointer; pointer=nullptr;}

class IApple
{
public:
 virtual void Show() = 0;
};

class ChinaApple :public IApple
{
public:
    ChinaApple() {}
    virtual ~ChinaApple(){}
    virtual void Show()
    {
        cout << "china apple" << endl;
    }
};

class USAApple :public IApple
{
public:
    USAApple() {}
    virtual ~USAApple(){}
    virtual void Show()
    {
        cout << "USA apple" << endl;
    }
};

class IBanana
{
public:
    virtual void Name() = 0;
};
class ChinaBanana :public IBanana
{
public:
    ChinaBanana() {}
    virtual ~ChinaBanana(){}
    virtual void Name()
    {
        cout << "china banana" << endl;
    }
};

class USABanana :public IBanana
{
public:
    USABanana() {}
    virtual ~USABanana(){}
    virtual void Name()
    {
        cout << "USA banana" << endl;
    }
};

class IFactory
{
public:
    virtual IApple * CreateApple() = 0;
    virtual IBanana * CreateBanana() = 0;
};

class ChinaFacotry :public IFactory
{
public:
    ChinaFacotry(){}
    virtual ~ChinaFacotry(){}

    virtual IApple* CreateApple()
    {
        return new ChinaApple;
    }

    virtual IBanana* CreateBanana()
    {
        return new ChinaBanana;
    }
};

class USAFactory:public IFactory
{
public:
    USAFactory(){}
    virtual ~USAFactory(){}

    virtual IApple* CreateApple()
    {
        return new USAApple;
    }

    virtual IBanana* CreateBanana()
    {
        return new USABanana;
    }
};

int main()
{
    IFactory* factory = new ChinaFacotry();
    IApple* apple = factory->CreateApple();
    apple->Show();
    DELETE(apple);
    DELETE(factory);
    
    factory = new USAFactory();
    IBanana* banana = factory->CreateBanana();
    banana->Name();
    DELETE(banana);
    DELETE(factory)
    return 0;
}

